package com.dddd.blog.blogsp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dddd.blog.blogcommon.constant.ResultCode;
import com.dddd.blog.blogcommon.utils.ResultUtils;
import com.dddd.blog.blogsp.entity.Author;
import com.dddd.blog.blogsp.mapper.BlogAuthorMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 喵星球的大橘
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AuthorServiceImpl extends ServiceImpl<BlogAuthorMapper,Author> implements AuthorService {

    @Resource
    private BlogAuthorMapper blogAuthorMapper;


    @Override
    public List<String> getAuthorNameList() {

        List<String> authorList = blogAuthorMapper.getAuthorNameList();

        return authorList;
    }

    /**
     * 获取Author Map
     * @return
     */
    @Override
    public List<Map<String, Object>> getAuthorList() {

        QueryWrapper<Author> wrapper = new QueryWrapper();

        wrapper.select("distinct username,uuid,home_link,create_time");

        List<Map<String, Object>> authorList = blogAuthorMapper.selectMaps(wrapper);

        return authorList;

//        List<Map<String, Object>> authorList = blogAuthorMapper.getAuthorList();

    }

    /**
     * 分页获取Author Map
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public List<Map<String, Object>> getAuthorListPage(long currentPage, long pageSize) {


        Page page = new Page(currentPage, pageSize);

        QueryWrapper<Author> wrapper = new QueryWrapper();

        wrapper.select("distinct username,id,uuid,home_link,create_time");

        blogAuthorMapper.selectMapsPage(page,wrapper);

        return page.getRecords();
    }
}
